package com.easy.controller;

import com.easy.bean.Collect;
import com.easy.bean.User;
import com.easy.service.ICollectService;
import com.easy.util.LayData;
import com.easy.util.Page;
import com.easy.util.SYS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("collect")
public class CollectController {
    @Autowired
    ICollectService collectService;

    @RequestMapping("list")
    @ResponseBody
    public LayData getCollectList(Page page, String text){
        List<Collect> list=collectService.getCollectList(page,text);
        int count=collectService.CollectCount(text);
        return new LayData(count,list);
    }

    @RequestMapping("delete")
    @ResponseBody
    public int deleteCollect(HttpSession session,int proid){
        User loginUser=(User)session.getAttribute(SYS.SHOPPING_LOGIN_USER);
        int userid=loginUser.getId();
        return collectService.deleteCollect(userid,proid);
    }

    @RequestMapping("add")
    @ResponseBody
    public int addCollect(HttpSession session,Collect collect){
        User loginUser=(User)session.getAttribute(SYS.SHOPPING_LOGIN_USER);
        collect.setUserid(loginUser.getId());
        return collectService.addCollect(collect);
    }

    @RequestMapping("edit")
    @ResponseBody
    public int editCollect(HttpSession session,Collect collect){
        User loginUser=(User)session.getAttribute(SYS.SHOPPING_LOGIN_USER);
        collect.setUserid(loginUser.getId());
        return collectService.editCollect(collect);
    }

    @RequestMapping("get")
    @ResponseBody
    public List<Collect> collectList(HttpSession session){
        User loginUser=(User)session.getAttribute(SYS.SHOPPING_LOGIN_USER);
        int userid=loginUser.getId();
        return collectService.collectList(userid);
    }


}
